package com.humngyang.com.hmy.study.springtest.mybatis;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.lang.Nullable;

import java.lang.reflect.Proxy;


//@Component 不能使用@component,因为使用component的话，就会去扫描包，很麻烦
public class HmyFracoryBean implements FactoryBean {
    Class mapperInterface;

    public HmyFracoryBean(Class mapperInterface) {
        this.mapperInterface =mapperInterface;
    }

    @Nullable
    @Override
    public Object getObject() throws Exception {
        Class[] clazzs  = new Class[]{mapperInterface};
        Object o =  Proxy.newProxyInstance(MybatisProxy.class.getClassLoader(),
                clazzs,
                new HmyInvocationHandler());
        return o;
    }

    @Nullable
    @Override
    public Class<?> getObjectType() {
        return mapperInterface;
    }
}
